import VueRouter from  "vue-router";
import Message from "element-ui/packages/message/src/main";
import demo from '@/page/demo'
import updatepwd from '@/page/updatepwd'
import supplier from '@/page/supplier'
import addsuppplier from '@/page/addsuppplier'
import purchase from '@/page/purchase'
import Jurisdiction from '@/page/Jurisdiction'
import Audit from '@/page/Audit'
import reqister from '@/page/reqister'
import DepaCollection from '@/page/DepaCollection'
import MatLending from '@/page/MatLending'

import matlendAudit from '@/page/matlendAudit'
import Stock from '@/page/Stock'
import Lossreport from '@/page/Lossreport'
import MatAdministration from '@/page/MatAdministration'
import LossAdministration from '@/page/LossAdministration'
import Purquiry from '@/page/Purquiry'
import Warquery from '@/page/Warquery'
import Depquiry from '@/page/Depquiry'
import Depsummary from '@/page/Depsummary'
import indeximg from '@/page/indeximg'
import Addmaterials from '@/page/Addmaterials'

let router =new VueRouter({
    routes:[
        {path:'/',redirect:'/login'},
        {path:'/login',meta:{name:"登陆页面"},component:()=>import('@/page/login')},


        {path:'/index',meta:{name:"首页"},redirect:'indeximg',component:()=>import('@/page/index')
            ,children:[
                {path:'/demo',meta:{name:"用户管理页面"},components:{text:demo}},
                {path:'/updatepwd',meta:{name:"修改密码界面"},components:{text:updatepwd}},
                {path:'/supplier',meta:{name:"供应商界面"},components:{text:supplier}},
                {path:'/addsuppplier',meta:{name:"添加供应商界面"},components:{text:addsuppplier}},
                {path:'/purchase/:group',meta:{name:"采购登记界面"},components:{text:purchase}},
                {path:'/Jurisdiction',meta:{name:"修改用户权限界面"},components:{text:Jurisdiction}},
                {path:'/Audit',meta:{name:"审核入库界面"},components:{text:Audit}},
                {path:'/reqister',meta:{name:"用户注册界面"},components:{text:reqister}},
                {path:'/DepaCollection',meta:{name:"部门领用界面"},components:{text:DepaCollection}},
                {path:'/MatLending',meta:{name:"物资借出界面"},components:{text:MatLending}},
                {path:'/matlendAudit',meta:{name:"借出审核界面"},components:{text:matlendAudit}},
                {path:'/Stock',meta:{name:"库存盘点界面"},components:{text:Stock}},
                {path:'/Lossreport',meta:{name:"部门报损界面"},components:{text:Lossreport}},
                {path:'/MatAdministration',meta:{name:"物资管理界面"},components:{text:MatAdministration}},
                {path:'/LossAdministration',meta:{name:"部门管理界面"},components:{text:LossAdministration}},
                {path:'/Purquiry',meta:{name:"采购单查询界面"},components:{text:Purquiry}},
                {path:'/Warquery',meta:{name:"入库查询界面"},components:{text:Warquery}},
                {path:'/Depquiry',meta:{name:"部门领用查询界面"},components:{text:Depquiry}},
                {path:'/Depsummary',meta:{name:"部门领用汇总界面"},components:{text:Depsummary}},
                {path:'/indeximg',meta:{name:"部门领用汇总界面"},components:{text:indeximg}},
                {path:'/Addmaterials',meta:{name:"添加物品界面"},components:{text:Addmaterials}},

            ]},

    ],
    mode: 'history'
});

let notNeedLogin=['/login','/reqister'];
router.beforeEach((to, from, next) => {
    if(notNeedLogin.indexOf(to.path)===-1){
        if(localStorage.getItem('TOKEN')==null){
            Message.warning('请登录');
            next('/login');
        }
    }
    document.title=to.meta.name;
    next();

    })



export  default router